package com.qianfeng.smartdevice.mapper;

import com.qianfeng.smartdevice.pojo.SysUserOnline;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * Created by wenka on 2022/3/17 13:46
 *
 * @author Jackiechan
 * @version 1.0
 * @since 1.0
 */
public interface SysUserOnlineMapper {
    /**
     * 保存数据
     *
     * @param sysUserOnline
     */
    @Insert("insert into sys_user_online values(#{sessionId},#{loginName},#{ipaddr},#{loginLocation},#{browser},#{os},#{status},#{startTimestamp},#{lastAccessTime},#{expireTime})")
    void addSysUserOnline(SysUserOnline sysUserOnline);

    /**
     * 根据用户名查找
     * @param loginName
     * @return
     */
    @Select("SELECT COUNT(*) FROM sys_user_online WHERE login_name=#{loginName} ")
    int findByUserName(String loginName);

    /**
     * 更新用户在线状态
     * @param sysUserOnline
     */
    @Update("UPDATE sys_user_online SET sessionId=#{sessionId},ipaddr=#{ipaddr},login_location=#{loginLocation},browser=#{browser},os=#{os},status=#{status},start_timestamp=#{startTimestamp},last_access_time=#{lastAccessTime},expire_time=#{expireTime} WHERE login_name=#{loginName}")
    void updateSysUserOnline(SysUserOnline sysUserOnline);

}
